﻿using BLL;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Com.Qkds.Erp.WebUi
{
    public partial class informList : System.Web.UI.Page
    {
        public int pid
        {
            get
            {
                return int.Parse(ViewState["pid"].ToString());
            }
            set
            {
                ViewState["pid"] = value;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            

            if (!IsPostBack)
            {
                pid = 0;
                string tablename = "EmployeeType";
                this.ddEmployTypeID.DataSource = new informBLL().Select(tablename);
                this.ddEmployTypeID.DataValueField = "ID";
                this.ddEmployTypeID.DataTextField = "Name";
                this.ddEmployTypeID.DataBind();
                if (Request["id"] != null)
                {
                    string TableName = "Employee";
                    pid = int.Parse(Request["ID"].ToString());
                    EmployeeModel model = new informBLL().GetModelByID(TableName, pid);
                    this.ddEmployTypeID.SelectedValue = model.EmployeeTypeID.ToString();
                    this.txtName.Value = model.EmployeeName;
                    this.txtAge.Value = model.Age;
                    this.txtSex.Value=model.Sex;
                    this.txtAddress.Value = model.Address;
                    this.txtCall.Value = model.Call;
                    this.txtWages.Value = model.Wages;
                }

            }
        }

        

        protected void btnSave_ServerClick(object sender, EventArgs e)
        {
            EmployeeModel model = new EmployeeModel()
            {
                
                EmployeeTypeID = int.Parse(this.ddEmployTypeID.SelectedValue),
                EmployeeName = this.txtName.Value,
                Sex = this.txtSex.Value,
                Age = this.txtAge.Value,
                Address = this.txtAddress.Value,
                Call = this.txtCall.Value,
                Wages = this.txtWages.Value
            };
            informBLL bll = new informBLL();
            if (pid > 0)
            {
                bll.Gai(model, pid);

            }
            else
            {
                bll.Add(model);


            }
            Response.Redirect("inform.aspx");
        }
    }
}